﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WealowsHospital
{
    public partial class FrmAddRole : Form
    {
        private WellmeadowsEntities hospital;
        BLL.StaffBus bus;
        public FrmAddRole()
        {
            InitializeComponent();
            hospital = new WellmeadowsEntities();
            bus = new WealowsHospital.BLL.StaffBus(hospital);
            DisplayRole();
        }

        private void btnAddRole_Click(object sender, EventArgs e)
        {
            btnAddRole.Enabled = false;
            try
            {
               
                if (bus.AddRole(txtRole.Text))
                {
                    MessageBox.Show("Create Role Successfully");
                    DisplayRole();
                    
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Cannot Create This Role");
            }
            btnAddRole.Enabled = true;
            

        }

        private void DisplayRole()
        {
            List<Role> roles = hospital.Role.ToList();
            grvRoles.DataSource = roles;
        }

        private void FrmAddRole_Load(object sender, EventArgs e)
        {

        }

        private void FrmAddRole_FormClosing(object sender, FormClosingEventArgs e)
        {
            hospital.Dispose();
        }
    }
}
